/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.org.ccb.ccbadm.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "administracao")
//mysql não suporta sequencia ...
//@SequenceGenerator(name = "administracao_seq", sequenceName = "administracao_seq", allocationSize = 1)
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Administracao.findAll", query = "SELECT a FROM Administracao a"),
    @NamedQuery(name = "Administracao.findById", query = "SELECT a FROM Administracao a WHERE a.id = :id"),
    @NamedQuery(name = "Administracao.findByNome", query = "SELECT a FROM Administracao a WHERE a.nome = :nome"),
    @NamedQuery(name = "Administracao.findByCodigo", query = "SELECT a FROM Administracao a WHERE a.codigo = :codigo"),    
    @NamedQuery(name = "Administracao.findByCnpj", query = "SELECT a FROM Administracao a WHERE a.codigo = :cnpj"),
    @NamedQuery(name = "Administracao.findByEmail", query = "SELECT a FROM Administracao a WHERE a.email = :email")})
public class Administracao implements Serializable{
    @ManyToMany(mappedBy = "administracaoList")
    private List<Usuario> usuarioList;  
    
//    @OneToMany(mappedBy = "administracaoList")
//    private List<Templo> temploList;      
    
//    @JoinTable(name = "administracao_telefone", joinColumns = {
//        @JoinColumn(name = "administracao_id", referencedColumnName = "id")}, inverseJoinColumns = {
//        @JoinColumn(name = "telefone_id", referencedColumnName = "id")})
//    @OneToMany
//    private List<Telefone> telefoneList;
    
//    @JoinTable(name = "administracao_conta", joinColumns = {
//        @JoinColumn(name = "administracao_id", referencedColumnName = "id")}, inverseJoinColumns = {
//        @JoinColumn(name = "conta_id", referencedColumnName = "id")})
//    @OneToMany
//    private List<Conta> contaList;    
    
    @Id
    @Basic(optional = false)
    @NotNull
    //@GeneratedValue(generator="administracao_seq", strategy = GenerationType.SEQUENCE)      
    @Column(name = "id")
    private Integer id;
    @NotNull    
    @Size(max = 200) 
    @Column(name = "nome")
    private String nome;
    @NotNull    
    @Size(max = 6)
    @Column(name = "codigo")
    private String codigo;  
    @NotNull    
    @Size(max = 15)
    @Column(name = "cnpj", unique = true)
    private String cnpj;  
    @Size(max = 200)
    @Column(name = "email")
    private String email; 
    @Column(name = "desativado", nullable = false)
    private Boolean desativado;

//    @JoinColumn(name = "endereco_id", referencedColumnName = "id")
//    @OneToOne
//    private Endereco enderecoId;    
    public Administracao() {
        
    }
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getCnpj() {
        return cnpj;
    }

    public void setCnpj(String cnpj) {
        this.cnpj = cnpj;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean isDesativado() {
        return desativado;
    }

    public void setDesativado(Boolean desativado) {
        this.desativado = desativado;
    }

    public List<Usuario> getUsuarioList() {
        return usuarioList;
    }

    public void setUsuarioList(List<Usuario> usuarioList) {
        this.usuarioList = usuarioList;
    }    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Administracao other = (Administracao) obj;
        if ((this.cnpj == null) ? (other.cnpj != null) : !this.cnpj.equals(other.cnpj)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Administracao{" + "id=" + id + ", nome=" + nome + ", codigo=" + codigo + ", cnpj=" + cnpj + ", desativado=" + desativado + '}';
    }
    
}
